package com.sprucetec.live.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

public class GenerateRandomNum {

	public static String getRandomNum(int count){
        StringBuffer sb = new StringBuffer();
        String str = "0123456789";
        Random r = new Random();
        for(int i=0;i<count;i++){
            int num = r.nextInt(str.length());
            sb.append(str.charAt(num));
            str = str.replace((str.charAt(num)+""), "");
        }
        return sb.toString();
   }
   
   public static String buildOrderFlow(){
		String reqTime = new SimpleDateFormat("yyMMddHHmmss").format(new Date());
		return reqTime + getRandomNum(4);
   }
   
   public static String buildByUUId() {
	   int first = new Random(10).nextInt(8) + 1;
       int hashCodeV = UUID.randomUUID().toString().hashCode();
       if (hashCodeV < 0) {//有可能是负数
           hashCodeV = -hashCodeV;
       }
       // 0 代表前面补充0
       // 4 代表长度为4
       // d 代表参数为正数型
       return first + String.format("%015d", hashCodeV);
   }
   
   public static void main(String[] args) {
	   System.out.println(GenerateRandomNum.getRandomNum(5));
	   System.out.println(GenerateRandomNum.buildByUUId());
   }
	
}
